package edu.hcnu.expception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class AppException {

    @ExceptionHandler(NotAuthorizedException.class)
    @ResponseStatus(HttpStatus.FORBIDDEN)
    @ResponseBody
    public Map<String, Object> handleNotAuthorizedException(NotAuthorizedException e){
        HashMap<String, Object> res = new HashMap<>();
        res.put("status",HttpStatus.FORBIDDEN);
        res.put("message",e.getMessage());
        return  res;
    }
}
